<% breadcrumb :attendees%>

<div class="row">
  <div class="col-lg-12">
    <div class="ibox float-e-margins">
      <div class="ibox-title">
        <h5>报名用户管理_共找到 <strong class="text-success"><%= @attendees.total_count %></strong> 条记录</h5>
      </div>
      <div class="ibox-content">
        <div class="row">
          <div class="col-xs-12 text-right">
            <%= link_to '下载模板', templates_path(filename: 'attendee.xls'), class: 'btn btn-white btn-sm' %>
            <%= link_to '添加报名用户', new_event_attendee_path, class: 'btn btn-white btn-sm' %>
            <%= link_to '报名数据导出', event_export_path, class: 'btn btn-white btn-sm m-r-md' %>
            <form action="/app/events/<%= current_event.id %>/attendees" class='form-inline pull-right' method="post" name="fileForm" multipart='true' enctype="multipart/form-data" onsubmit="return validate_form(this);">
              <div class="form-group">
                <%= file_field_tag :attendee_file, class: 'form-control' %>
              </div>
              <button id="import-attendee" class="btn btn-sm btn-white" type="submit">导入</button>
              <% if params[:path] %>
                <a class="btn btn-danger" href="<%= params[:path] %>" target="_blank">查看错误日志</a>
              <% end %>
            </form>
          </div>
        </div>

        <%= render 'filter' %>

        <div class="table-responsive">
          <table class="table table-striped">
            <thead>
            <tr>
              <th>序号</th>
              <th>姓名</th>
              <th>rfid</th>
              <!-- <th>主嘉宾</th> -->
              <!-- <th>对应销售</th> -->
              <th>性别</th>
              <th>报名时间</th>
              <th>省</th>
              <th>市</th>
              <th>公司</th>
              <th>手机号码</th>
              <th>标签</th>
              <th class="text-center">照片</th>
              <th class="text-center">头像</th>
              <th>管理</th>
            </tr>
            </thead>
            <tbody>
            <% @attendees.each do |attendee| %>
              <tr>
                <td><%=attendee.attendee_number%></td>
                <td><%=attendee.name%></td>
                <td><%=attendee.rfid_num%></td>
                <!-- <td><%=attendee.owner_attendee.try(:name)%></td>
                <td><%=attendee.seller.try(:name)%></td> -->
                <td><%=attendee.gender%></td>
                <td><%=attendee.created_at%></td>
                <td><%=attendee.province%></td>
                <td><%=attendee.city%></td>
                <td><%=attendee.company%></td>
                <td><%=attendee.mobile%></td>
                <td><%=attendee.category.try(:name)%></td>
                <td class="text-center">
                  <% if attendee.photo.exists? %>
                    <%= link_to attendee.photo.url, target: '_blank' do%> <i class="fa fa-picture-o text-success"></i> <% end %>
                  <% end %>
                </td>
                <td class="text-center">
                  <% if attendee.avatar.exists? %>
                    <%= link_to attendee.avatar.url, target: '_blank', class:'btn btn-normal btn-xs' do%>
                      <i class="fa fa-smile-o text-success"></i>
                    <% end %>
                  <% elsif attendee.photo.exists? %>
                    <%= link_to avatar_event_attendee_path(current_event, attendee, back_url: request.original_url ), class:'btn btn-xs btn-outline btn-normal' do %>
                      <i class="fa fa-frown-o text-danger"></i>
                    <% end %>
                  <% end %>
                </td>
                <td>
                  <%=link_to '查看', event_attendee_path(current_event, attendee), class: 'btn btn-white btn-xs' %>
                  <%=link_to '编辑', edit_event_attendee_path(current_event, attendee), class: 'btn btn-white btn-xs' %>
                </td>
              </tr>
            <% end %>
            </tbody>
          </table>

        </div>

        <div class="row">
          <div class="col-sm-12">
            <%= paginate @attendees %>
          </div>
        </div>

      </div>
    </div>
  </div>
</div>

<script type="text/javascript">
function validate_form(thisform)
{
  var fileName = document.forms["fileForm"]["attendee_file"].value;
  if(fileName&&fileName.split(".")[1]!="xls"){
    alert('请上传xls格式的文件');
    return false;
  }
  var current_time = 0;
  if (fileName){
    setInterval(function(){
      current_time++;
      var textString = "";
      for(var i=0; i<(current_time%3); i++){
        textString += ".";
      }
      $('#import-attendee').text('数据导入中， 请稍后'+textString);
    },
      500);
    return true;
  }
  else{
    alert('请选择要上传的文件');
    return false;
  }
}
</script>
